

<%@ page language="java" contentType="text/html" session="true" %>
<%@ page import="camel.client.CamelRemote"%>
<%@ page import="java.util.Properties"%>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="camel.client.ParticipantLoginInfo" %>
<%@ page import="camel.client.SessionTicket"%>
<%@ page import="camel.client.ParticipantLoginInfo"%>

<%
 
    String id = request.getParameter("id");
    String pswd = request.getParameter("pswd");
    out.println("id" + id);
    
    if(session.isNew()) {
		session.setAttribute("login.id", id);
		session.setAttribute("login.passwd", pswd);
    }
%>

<%  
	InitialContext ic;
		try {
			Properties props = new Properties();
			props.put("java.naming.provider.url", "jnp://localhost:1099");
            props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");  
		//	System.out.println ( "Create init context");
			ic = new InitialContext(props);
			CamelRemote remote = (CamelRemote)ic.lookup("Camel");
			
			
			ParticipantLoginInfo info = new ParticipantLoginInfo();
			info.setUsername(id);
			info.setPassword(pswd);
			System.out.println("id" + id);
			System.out.println("pswd"  + pswd);
			
			SessionTicket ticket = remote.login(info);
			System.out.println("isLogin" + ticket.isLogInSuccessful());
			
			if (!ticket.isLogInSuccessful()) {
				out.print("<script language='JavaScript'>");
				out.print("	alert('wrong');");
				out.print("	parent.frm.id.value='';");
				out.print("	parent.frm.pswd.focus();");			
				out.print("</script>");
			
			}
			else {
				out.print("<script language='JavaScript'>");														
				out.print("	alert('login success');");
				out.print("	parent.location.href = 'frame.jsp'; "); 		
				out.print("	document.location.href='about:blank;'");
				out.print("</script>");
				session.setAttribute("ic",ic);
				session.setAttribute("remote",remote);
				session.setAttribute("ticket",ticket);
			}
		
    	} catch (Exception e) {
	    	e.printStackTrace();
	    	out.print("<script language='JavaScript'>");
			out.print("	alert('error');");
			out.print("	document.location.href='about:blank;'");
			out.print("</script>");
    }
%>
